package edu.cgpi.core.entidade;

import java.util.HashSet;
import java.util.Set;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.annotations.XStreamOmitField;

public class Retangulo implements FormaGeometrica {
	
	@XStreamImplicit
	public Ponto[] pontos = new Ponto[2];
	@XStreamOmitField
	private Reta diagonal;

	public Retangulo(Ponto verticeInicial, Ponto verticeOposto) {
		pontos[0] = verticeInicial;
		pontos[1] = verticeOposto;
		diagonal = new Reta(verticeInicial, verticeOposto);
	}
	
	public Reta getDiagonal() {
		return diagonal;
	}
	
	public void setDiagonal(Reta diagonal) {
		this.diagonal = diagonal;
	}

	public Ponto obterLocalizacao() {
		Double minX = Math.min(diagonal.getPonto1().getX(), diagonal.getPonto2().getX());
		Double minY = Math.min(diagonal.getPonto1().getY(), diagonal.getPonto2().getY());
		return new Ponto(minX, minY);
	}
	
	public Double obterLargura() {
		return Math.abs(diagonal.getPonto1().getX() - diagonal.getPonto2().getX());
	}
	
	public Double obterAltura() {
		return Math.abs(diagonal.getPonto1().getY() - diagonal.getPonto2().getY());
	}

	public Set<Ponto> obterPontos() {
		Ponto vertice2 = new Ponto(diagonal.getPonto2().getX(), diagonal.getPonto1().getY());
		Ponto vertice4 = new Ponto(diagonal.getPonto1().getX(), diagonal.getPonto2().getY());
		Reta reta1 = new Reta(diagonal.getPonto1(), vertice2);
		Reta reta2 = new Reta(vertice2, diagonal.getPonto2());
		Reta reta3 = new Reta(diagonal.getPonto2(), vertice4);
		Reta reta4 = new Reta(vertice4, diagonal.getPonto1());

		Set<Ponto> pontos = new HashSet<Ponto>();
		pontos.addAll(reta1.obterPontos());
		pontos.addAll(reta2.obterPontos());
		pontos.addAll(reta3.obterPontos());
		pontos.addAll(reta4.obterPontos());
		return pontos;
	}

	@Override
	public Double calcularDistancia(FormaGeometrica forma) {
		// TODO Auto-generated method stub
		return null;
	}
}